import requests
import execjs
import os

js_path = os.path.join(os.path.dirname(__file__), 'qcchmac.js')
with open(js_path, 'r', encoding='utf-8') as f:  # Changed encoding to utf-8
    js_code = f.read()
    
js = execjs.compile(js_code)
result = js.call('get_header', {'searchKey': '东软', 'pageIndex': 2, 'pageSize': 20})  # Added required parameter
print(result['u'])

# ... rest of your existing code ...clear

cookies = {
    'QCCSESSID': '8a4a2b5be134d72b522a664a36',
    'qcc_did': '753e8ea2-da8a-4847-900a-1c71d5690342',
    'UM_distinctid': '1966695eb091388-033e93f82ea8648-4c657b58-1bcab9-1966695eb0a2639',
    'tfstk': 'gIPs91xRBhx_Skt3SGQEPZAVCehbco1rcEgYrrdwkfh9DnU-YVPNjrnbcko3cxbi0mnb0reN8_5zSPcmMnsPa_5rkNv0fnhxHZdKSq_EWB7D1xcmMgSEC7el-jqT5gbLMyQIuqR96on9vDnnWqhxXxKpp4nKDjExDBnKy4ixWddARynnkjnYDjHHu3ufuca1Sguc2QJSEPnBMIFOiAi5VD3nRWgtC0HKAIe_OVMs2PFW1cTqJWPIUv8VEXUuLl3IN6JtwywYV8EcUpc_kREmdljHdDyLsrnxCEduRzaTeXFVkUDQvqM-MvTvMyGicYPtw_KI-JUaH5q6lI3g_7kjqv_vixlLaYe8fEbuJf3YmYVVqCmTkzVuUb1eBbUQHuwf4xdrV-U6heMkG2iPRw9DnTryKyIJEJ8SB20sOw_BfXHt-2iPRw9DnA3n8p_CRhGd.',
    'CNZZDATA1254842228': '415518209-1745477823-https%253A%252F%252Fcn.bing.com%252F%7C1745497103',
    'acw_tc': '1a0c39d317454991329231408e0069f1cfa09cf15bbe58778b13d66fd5d550',
}

headers = {
    'accept': 'application/json, text/plain, */*',
    'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'cache-control': 'no-cache',
    'content-type': 'application/json',
    result['i'] : result['u'],
    'origin': 'https://www.qcc.com',
    'pragma': 'no-cache',
    'priority': 'u=1, i',
    'referer': 'https://www.qcc.com/web/search?key=%E4%B8%9C%E8%BD%AF',
    'sec-ch-ua': '"Microsoft Edge";v="135", "Not-A.Brand";v="8", "Chromium";v="135"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sec-fetch-dest': 'empty',
    'sec-fetch-mode': 'cors',
    'sec-fetch-site': 'same-origin',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0',
    'x-pid': 'bb3763e5d17d90e2d10d5c8c0e20fd67',
    'x-requested-with': 'XMLHttpRequest',
    # 'cookie': 'QCCSESSID=8a4a2b5be134d72b522a664a36; qcc_did=753e8ea2-da8a-4847-900a-1c71d5690342; UM_distinctid=1966695eb091388-033e93f82ea8648-4c657b58-1bcab9-1966695eb0a2639; tfstk=gIPs91xRBhx_Skt3SGQEPZAVCehbco1rcEgYrrdwkfh9DnU-YVPNjrnbcko3cxbi0mnb0reN8_5zSPcmMnsPa_5rkNv0fnhxHZdKSq_EWB7D1xcmMgSEC7el-jqT5gbLMyQIuqR96on9vDnnWqhxXxKpp4nKDjExDBnKy4ixWddARynnkjnYDjHHu3ufuca1Sguc2QJSEPnBMIFOiAi5VD3nRWgtC0HKAIe_OVMs2PFW1cTqJWPIUv8VEXUuLl3IN6JtwywYV8EcUpc_kREmdljHdDyLsrnxCEduRzaTeXFVkUDQvqM-MvTvMyGicYPtw_KI-JUaH5q6lI3g_7kjqv_vixlLaYe8fEbuJf3YmYVVqCmTkzVuUb1eBbUQHuwf4xdrV-U6heMkG2iPRw9DnTryKyIJEJ8SB20sOw_BfXHt-2iPRw9DnA3n8p_CRhGd.; CNZZDATA1254842228=415518209-1745477823-https%253A%252F%252Fcn.bing.com%252F%7C1745497103; acw_tc=1a0c39d317454991329231408e0069f1cfa09cf15bbe58778b13d66fd5d550',
}

json_data = {
    'searchKey': '东软',
    'pageIndex': 2,
    'pageSize': 20,
}
proxies = {
  "http": "http://127.0.0.1:7890",
  "https": "http://127.0.0.1:7890",
}
response = requests.post('https://www.qcc.com/api/search/searchMulti', cookies=cookies, headers=headers, json=json_data,proxies=proxies)
print(response.text)
# Note: json_data will not be serialized by requests
# exactly as it was in the original request.
#data = '{"searchKey":"东软","pageIndex":2,"pageSize":20}'.encode()
#response = requests.post('https://www.qcc.com/api/search/searchMulti', cookies=cookies, headers=headers, data=data)